package com.tyc.threalpool;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.*;

/**
 * 类描述
 *
 * @author tyc
 * @version 1.0
 * @date 2023-01-11 10:56:44
 */
public class Demo05 {
    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(1,
                1,
                1,
                TimeUnit.SECONDS, new SynchronousQueue<>(),
                new ThreadFactoryBuilder().setNameFormat("consumer-pool-%d").build());
        for (int i = 0; i < 10; i++) {
            try {
                executor.execute(()->{
                    test();
                });
            } catch (RejectedExecutionException e) {
                e.printStackTrace();
            }
        }
    }

    public static void test(){
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
